<!DOCTYPE html>
<html class="x-admin-sm">
{include file="public/head"}
<body>
<div class="layui-fluid">
    <div class="layui-row">
        <form class="layui-form">
            <div class="layui-form-item">
                <label for="username" class="layui-form-label">
                    <span class="x-red">*</span>登录名
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="username" name="username" required="" lay-verify="required"
                           autocomplete="off" class="layui-input" value="{$username}">
                </div>
                <div class="layui-form-mid layui-word-aux">
                    <span class="x-red">*</span>将会成为您唯一的登入名
                </div>
            </div>
            <div class="layui-form-item">
                <label for="L_pass" class="layui-form-label">
                    <span class="x-red">*</span>旧的密码
                </label>
                <div class="layui-input-inline">
                    <input type="password" id="L_pass" name="L_pass" required="" lay-verify=""
                           autocomplete="off" class="layui-input">
                </div>
                <div class="layui-form-mid layui-word-aux">
                    6到16个字符
                </div>
            </div>
            <div class="layui-form-item">
                <label for="N_pass" class="layui-form-label">
                    <span class="x-red">*</span>新的密码
                </label>
                <div class="layui-input-inline">
                    <input type="password" id="N_pass" name="pass" required="" lay-verify="pass"
                           autocomplete="off" class="layui-input">
                </div>
                <div class="layui-form-mid layui-word-aux">
                    6到16个字符
                </div>
            </div>
            <div class="layui-form-item">
                <label for="N_repass" class="layui-form-label">
                    <span class="x-red">*</span>确认密码
                </label>
                <div class="layui-input-inline">
                    <input type="password" id="N_repass" name="repass" required="" lay-verify="repass"
                           autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label"></label>
                <button class="layui-btn" lay-filter="add" lay-submit="">
                    修改
                </button>
            </div>
        </form>
    </div>
</div>
<script>
    let url = '/admin/admin/accountedit'
    layui.use(['form', 'layer', 'jquery'], () => {
        $ = layui.jquery;
        var form = layui.form,
            layer = layui.layer;

        form.verify({
            pass: [/(.+){6,12}$/, '密码必须6到12位'],
            repass: function (value) {
                if ($('#N_pass').val() !== $('#N_repass').val()) {
                    return '两次密码不一致';
                }
            }
        });

        form.on('submit(add)', function (data) {
            data = data.field
            $.post(url, data, function (res) {
                if (res.status === config.success) {
                    layer.alert("修改成功", {icon: 6}, () => {
                        window.location.href = '/admin/logout'
                    });
                } else {
                    layer.msg(res.message, {icon: 2})
                }
            })
            return false;
        });
    });
</script>
</body>
</html>
